// pages/resume/index/index.js
const config = getApp().globalData.config
const T = getApp().globalData.T
let token = ''
Page({

  /**
   * 页面的初始数据
   */
  data: {
    key: '',
    index: '',
    tabs: [{
      key: 'tab1',
      title: '全职简历',
    },
    {
      key: 'tab2',
      title: '小时工简历',
    }
    ],
    statusColor: ['#353535', '#999999', '#FE7E3E', '#999999', '#2CA7E7', '#3CC095', '#999999','#FE7E3E'],
    pageSize: 10,
    isLoadedFull: false,
    isFirstTipFull: true,
    fullPage:1,
    fulltimeList:[],

    isLoadedHourly: false,
    isFirstTipHourly: true,
    hourlyPage: 1,
    hourlyList:[],
    isOpen1:false,
    isOpen2: false,

    typeList: [{ name: '全部简历', id: 0 }, { name: '收到的简历', id: 1 }, { name: '预约面试', id: 2 }, { name: '已面试', id: 3 }, { name: '成功入职', id: 4 }, { name: '预约失败', id: 5 }, { name: '面试失败', id: 6 }, { name: '收藏的简历', id: 7 }],
    type1:0,//筛选用到的type
    type2: 0,//筛选用到的type
    selStr1:'全部简历',
    selStr2: '全部简历',

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    token = getApp().globalData.token;
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 重置数据
    this.data.fulltimeList = [];
    this.data.isLoadedFull = false;
    this.data.fullPage = 1;
    this.data.isFirstTipFull = true ;

    this.data.hourlyList = [];
    this.data.isLoadedHourly = false;
    this.data.hourlyPage = 1;
    this.data.isFirstTipHourly = true;

    this.getFullTimeResume();
    this.getHourlyResume();
  },
  onSelectType(e){
    let name = e.currentTarget.dataset.name;
    let id = e.currentTarget.dataset.id;
    console.log(id);
if(this.data.index == 0){
  this.setData({ selStr1: name, isOpen1: false, type1: id });
  this.getFullTimeResume(true);
}else if(this.data.index == 1){
  this.setData({ selStr2: name, isOpen2: false, type2: id });
this.getHourlyResume(true);
}
    
  },
  onSel(){
    if(this.data.index == 0){
      this.setData({ isOpen1: true })

    }else{
      this.setData({ isOpen2: true })

    }
  },
  onSearch() {
    wx.navigateTo({
      url: '../search/search',
    })
  },

  toast(txt) {
    wx.showToast({
      title: txt,
      icon:'none'
    })
  },

  onTabsChange(e) {
    const {
      key
    } = e.detail;
    const index = this.data.tabs.map((n) => n.key).indexOf(key);

    this.setData({
      key,
      index,
    });
  },

  onSwiperChange(e) {
    const {
      current: index,
      source
    } = e.detail
    const {
      key
    } = this.data.tabs[index]

    if (!!source) {
      this.setData({
        key,
        index,
      })
    }
  },

  getFullTimeResume(isSel) {
    T.req({
      loadTitle: '加载中...',
      url: config.api + 'resume/full_time/list',
      method: 'GET',
      data: {
        token: token,
        type:this.data.type1,
        pageNo: this.data.fullPage,
        pageSize: this.data.pageSize
      },
      success: (res) => {
        if (res.rowCount == this.data.fulltimeList.length) {
          this.data.isLoadedFull = true;
          return ;
        }
        if(isSel){
          this.data.fulltimeList = [];
        }
        this.setData({
          fulltimeList: this.data.fulltimeList.concat(res.list)
        })
      }
    })
  },

  getHourlyResume (isSel) {
    T.req({
      loadTitle: '加载中...',
      url: config.api + 'resume/hourly_job/list',
      method: 'GET',
      data: {
        token: token,
        pageNo: this.data.hourlyPage,
        type:this.data.type2,
        pageSize: this.data.pageSize
      },
      success: (res) => {
        if (res.rowCount == this.data.hourlyList.length) {
          this.data.isLoadedHourly = true;
          return;
        }
        if(isSel){
          this.data.hourlyList = [];
        }
        this.setData({
          hourlyList: this.data.hourlyList.concat(res.list)
        })
      }
    })
  },

  onLoadMoreFull() {
    if (this.data.isLoadedFull) {
      if (this.data.isFirstTipFull) {
        this.toast('已加载完全部数据了');
      }
      this.data.isFirstTipFull = false;
      return ;
    }
    this.data.fullPage += 1;
    this.getFullTimeResume();
  },

  onLoadMoreHourly() {
    if (this.data.isLoadedHourly) {
      if (this.data.isFirstTipHourly) {
        this.toast('已加载完全部数据了');
      }
      this.data.isFirstTipHourly = false;
      return;
    }
    this.data.hourlyPage += 1;
    this.getHourlyResume();
  },

  jumpDetails(e) {
    console.log(e);
    let resumeId = e.currentTarget.dataset.resumeid;
    let type = e.currentTarget.dataset.type;
    if (type == 1) { // 全职
      let id = e.currentTarget.dataset.id;
      let status = e.currentTarget.dataset.status;
      let resumeDeliverId = e.currentTarget.dataset.resumedeliverid;
       wx.navigateTo({
         url: '../fulltime/detail?resumeId=' + resumeId + '&id=' + id + '&status=' + status + '&resumeDeliverId=' + resumeDeliverId,
       })

    } else {
      let id = e.currentTarget.dataset.id;
      let status = e.currentTarget.dataset.status;
      let resumeDeliverId = e.currentTarget.dataset.resumedeliverid;

      wx.navigateTo({
        url: '../hourly/detail?resumeId=' + resumeId + '&id=' + id + '&status=' + status + '&resumeDeliverId=' + resumeDeliverId,
      })
    }
  }
})